<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>工资信息管理系统</title>
		<link rel="stylesheet" type="text/css" href="js/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<script src="js/jquery-2.0.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/echarts.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/isLoginUser.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
		body {
			padding: 50px 50px;
		}

		.content {
			width: 400px;
		}

		.layui-btn {
			width: 290px;
			float: right;
			margin-top: 10px;
		}
	</style>
	<body>
		<div class="content">
			<div class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">原密码</label>
					<div class="layui-input-block">
						<input id="oldPassword" type="password" name="title" lay-verify="title" autocomplete="off" placeholder="请输入内容"
						 class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-block">
						<input id="newPassword1" type="password" name="title" lay-verify="title" autocomplete="off" placeholder="请输入内容"
						 class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">重复新密码</label>
					<div class="layui-input-block">
						<input id="newPassword2" type="password" name="title" lay-verify="title" autocomplete="off" placeholder="请输入内容"
						 class="layui-input">
					</div>
				</div>
				<button id="changePassword" type="button" class="layui-btn">修改</button>
			</div>
		</div>
		<script type="text/javascript">
			layui.use(['layer', 'element'], function() {
				$("#changePassword").click(function() {
					if ($("#oldPassword").val() == "" || $("#newPassword1").val() == "" || $("#newPassword2").val() == "") {
						layer.msg("请输入完整再提交");
					} else if( $("#newPassword1").val() != $("#newPassword2").val() ) {
						layer.msg("两次密码不一致，请重新输入");
					}else{
						$.ajax({
							url: "updateUserPassword",
							type: 'POST',
							data: {
								oldPassword: $("#oldPassword").val(),
								newPassword: $("#newPassword1").val(),
							},
							success: function(result) {
								if(result == 0){
									layer.msg('原密码错误，请重新输入');
								}else{
									layer.msg('修改成功，请重新登录');
									window.parent.open("login.html","_self");
								}
							},
							error: function(e) {
								console.log(e.status);
								layer.msg('修改失败');
							}
						});
					}
				});
			});
		</script>
	</body>
</html>
